/*
 * Pref.h
 * Copyright 2008 . All rights reserved.
 */

#import <Foundation/Foundation.h>
#import <sqlite3.h>

#define UK_GALLON 4.54609188

typedef enum {
	FUELLOG_NONE,
	FUELLOG_ODOMETER,
	FUELLOG_VOLUME,
	FUELLOG_COST,
	FUELLOG_UNITS
} PrefType;

#define DECIMAL_0 @"#"
#define DECIMAL_1 @"#.0"
#define DECIMAL_2 @"#.00"
#define DECIMAL_3 @"#.000"

typedef enum {
	ENGLISH,     // mpg
	METRIC,      // km/L
	GENERIC,    
	INV_METRIC,  // L/100km
	UK,          // mpg
	NORWAY       // L/10km
} UnitType;

#define GALLONS @"Gallons"
#define LITRES @"Litres"
#define VOLUME @"Fuel"

#define MILES @"Miles"
#define KILOMETRES @"Kilometres"
#define DISTANCE @"Distance"

#define MPG @"mpg"
#define KMPL @"km/L"
#define LPKM @"L/100km"
#define LPKM_NORWAY @"L/10km"
#define DPF @"Dist. / fuel"

#define CPM @"Cost per mile"
#define CPKM @"Cost per km"
#define CPD @"Cost / dist."

@interface Pref : NSObject {
    sqlite3 *database;
	int odometerDigits;
	int volumeDigits;
	int costDigits;
	int units;
	BOOL dirty;
	
	NSDateFormatter *dateFormatter;
	NSNumberFormatter *distanceFormatter;
	NSNumberFormatter *volumeFormatter;
	NSNumberFormatter *costFormatter;
	NSNumberFormatter *unitCostFormatter;
	
	NSString *distanceText;
	NSString *fuelText;
	NSString *dpfText;
	NSString *cpdText;
}

@property (nonatomic) sqlite3 *database;
@property (nonatomic) int odometerDigits;
@property (nonatomic) int volumeDigits;
@property (nonatomic) int costDigits;
@property (nonatomic) int units;
@property (nonatomic) BOOL dirty;

@property (nonatomic, assign) NSDateFormatter *dateFormatter;
@property (nonatomic, assign) NSNumberFormatter *distanceFormatter;
@property (nonatomic, assign) NSNumberFormatter *volumeFormatter;
@property (nonatomic, assign) NSNumberFormatter *costFormatter;
@property (nonatomic, assign) NSNumberFormatter *unitCostFormatter;
@property (nonatomic, assign) NSString *distanceText;
@property (nonatomic, assign) NSString *fuelText;
@property (nonatomic, assign) NSString *dpfText;
@property (nonatomic, assign) NSString *cpdText;

+ (void)finalizeStatements;

// static constructor
+ (Pref *)getAll:(sqlite3 *)db;

- (void)saveAll;
- (void)setPrefs:(int)newOdometerDigits volumeDigits:(int)newVolumeDigits costDigits:(int)newCostDigits units:(int)newUnits;

@end
